package rexsee.barcode;

import android.hardware.Camera;
import android.os.Handler;
import android.os.Message;

public class CameraAutoFocusCallback implements Camera.AutoFocusCallback {

	private static final long AUTOFOCUS_INTERVAL_MS = 1500L;
	private Handler autoFocusHandler;
	private int autoFocusMessage;
	void setHandler(Handler autoFocusHandler, int autoFocusMessage) {
		this.autoFocusHandler = autoFocusHandler;
		this.autoFocusMessage = autoFocusMessage;
	}
	@Override
	public void onAutoFocus(boolean success, Camera camera) {
		if (autoFocusHandler != null) {
			Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success);
			// Simulate continuous autofocus by sending a focus request every AUTOFOCUS_INTERVAL_MS milliseconds.
			autoFocusHandler.sendMessageDelayed(message, AUTOFOCUS_INTERVAL_MS);
			autoFocusHandler = null;
		}
	}

}
